<template>
  <div class="app-container">
    <!--按钮-->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['teacher:assessment:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['teacher:assessment:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['teacher:assessment:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['teacher:assessment:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getAssessment"></right-toolbar>
    </el-row>
    <!--表格-->
    <el-table border :data="assessmentList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="考核日期" align="center" prop="zdyja10301" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.zdyja10301, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="考核单位" align="center" prop="zdyja10302" />
      <el-table-column label="考核周期" align="center" prop="zdyja10303" />
      <el-table-column label="考核类型" align="center" prop="zdyja10304" />
      <el-table-column label="考核等次" align="center" prop="zdyja10305" />
      <el-table-column label="考核分数" align="center" prop="zdyja10306" />
      <el-table-column label="考核报告" align="center" prop="zdyja10308" />
      <el-table-column label="评语" align="center" prop="zdyja10307" />
      <el-table-column fixed="right" label="附件" align="center" prop="remark" width="200">
        <template slot-scope="{row}">
          <el-link :href="row.remark" target="_blank" class="buttonText"  type="primary" :underline="false">{{row.remark}}</el-link>
        </template>
      </el-table-column>
      <el-table-column fixed="right" label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-info"
            @click="handleDetail(scope.row)"
          >详情</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['teacher:assessment:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['teacher:assessment:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!--分页插件-->
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getAssessment"
    />

    <!-- 添加或修改考核信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
      <el-form v-bind:disabled="disabled" ref="form" :model="form" :rules="rules">
        <el-row gutter="15">
          <el-col :span="12">
            <el-form-item label="本人编号" prop="a00">
              <el-input v-model="form.a00" placeholder="请输入本人编号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="考核日期" prop="zdyja10301">
              <el-date-picker clearable size="small"
                              v-model="form.zdyja10301"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="选择考核日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row gutter="15">
          <el-col :span="12">
            <el-form-item label="考核单位" prop="zdyja10302">
              <el-input v-model="form.zdyja10302" placeholder="请输入考核单位" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="考核周期" prop="zdyja10303">
              <el-select v-model="form.zdyja10303" placeholder="请选择考核周期">
                <el-option
                  v-for="dict in zdyja10303Options"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row gutter="15">
          <el-col :span="12">
            <el-form-item label="考核类型" prop="zdyja10304">
              <el-input v-model="form.zdyja10304" placeholder="请输入考核类型" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="考核等次" prop="zdyja10305">
              <el-input v-model="form.zdyja10305" placeholder="请输入考核等次" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row gutter="15">
          <el-col :span="12">
            <el-form-item label="考核分数" prop="zdyja10306">
              <el-input v-model="form.zdyja10306" placeholder="请输入考核分数" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="评语" prop="zdyja10307">
              <el-input v-model="form.zdyja10307" type="textarea" placeholder="请输入内容" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row gutter="15">
          <el-col :span="12">
            <el-form-item label="考核报告" prop="zdyja10308">
              <el-input v-model="form.zdyja10308" type="textarea" placeholder="请输入内容" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
          </el-col>
        </el-row>
<!--        <el-form-item label="删除标识" prop="delFlag">-->
<!--          <el-input v-model="form.delFlag" placeholder="请输入删除标识" />-->
<!--        </el-form-item>-->

<!--        <el-form-item label="考核周期" prop="zdyja10303Text">-->
<!--          <el-input v-model="form.zdyja10303Text" placeholder="请输入考核周期" />-->
<!--        </el-form-item>-->
        <el-form-item label="附件" prop="remark">
          <fileUpload v-model="form.remark"/>
        </el-form-item>
      </el-form>
      <div v-show="!hidden" slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listAssessment, getAssessment, delAssessment, addAssessment, updateAssessment, exportAssessment } from "@/api/teacher/assessment";
import {selectAssessmentByA00} from "@/api/teacher/person";
import FileUpload from "@/components/FileUpload";

export default {
  name: "Assessment",
  components: {
    FileUpload
  },
  data() {
    return {
      hidden: false,
      //禁用状态
      disabled: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 考核信息表格数据
      assessmentList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 考核周期字典
      zdyja10303Options: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        a00: null,
        zdyja10302: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getAssessment();
    this.getDicts("sys_person_assessmentCycle").then(response => {
      this.zdyja10303Options = response.data;
    });
  },
  methods: {
    /** 查询考核信息列表 */
    getAssessment() {
      this.A00 = this.$route.query.A00
      selectAssessmentByA00(this.A00).then((response) => {
        this.assessmentList = response.rows;
      });
    },
    // 考核周期字典翻译
    zdyja10303Format(row, column) {
      return this.selectDictLabel(this.zdyja10303Options, row.zdyja10303);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        recordid: null,
        a00: null,
        zdyja10301: null,
        zdyja10302: null,
        zdyja10303: null,
        zdyja10304: null,
        zdyja10305: null,
        zdyja10306: null,
        zdyja10307: null,
        zdyja10308: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        delFlag: null,
        remark: null,
        zdyja10303Text: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getAssessment();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.recordid)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加考核信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.disabled = false
      this.hidden = false;
      this.reset();
      const recordid = row.recordid || this.ids
      getAssessment(recordid).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改考核信息";
      });
    },
    /** 详情按钮操作 */
    handleDetail(row) {
      this.hidden = true;
      this.disabled = true;
      this.reset();
      const recordid = row.recordid || this.ids
      getAssessment(recordid).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "考核信息详情";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.recordid != null) {
            updateAssessment(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getAssessment();
            });
          } else {
            addAssessment(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getAssessment();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const recordids = row.recordid || this.ids;
      this.$confirm('是否确认删除考核信息编号为"' + recordids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delAssessment(recordids);
        }).then(() => {
          this.getAssessment();
          this.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有考核信息数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportAssessment(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
    }
  }
};
</script>
